package maskWork;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;

public class Work implements Runnable {
	
	private ConcurrentLinkedQueue<Task> workQueue;
	
	private ConcurrentHashMap<String, Object> resultMap;
	
	
	public void setWorkQueue(ConcurrentLinkedQueue<Task> workQueue) {
		this.workQueue = workQueue;
	}

	public void setResultMap(ConcurrentHashMap<String, Object> resultMap) {
		this.resultMap = resultMap;
	}

	@Override
	public void run() {
		
		while (true) {
			Task task =  this.workQueue.poll();//取出一个任务并且删除
			if(task == null){
				break;
			}
			
			//业务处理，灵活处理
			Object result = MyWork.handler(task);
			
			this.resultMap.put(Integer.toString(task.getId()), result);
		}
	}
	
	public static Object handler(){
		return null;
	}

}
